<?php
class PortletUtil{
	
	public static function getFile($portlet){
		$portletFile = CMSPAD_PORTLET_ABSPATH . $portlet . '.php';
		if(file_exists($portletFile)){
			return $portletFile;
		}else{
			return null;
		}
	}
	
	public static function newObject($portlet){
		if(is_object($portlet)){
			return $portlet;
		}else{
			$portletFile = self::getFile($portlet);
			if($portletFile){
				include $portletFile;
				$portletClass = cmspad_get_class_name($portlet);
				if($portletClass){
					return new $portletClass();
				}else{
					return false;
				}
			}else{
				return null;
			}
		}
	}
	
	public static function newMethod($portlet,$method){
		$portletObj = self::newObject($portlet);
		if($portletObj){
			$method = cmspad_get_function_name($method,$portletObj);
			if(method_exists($portletObj,$method)){
				return array(&$portletObj,$method);
			}else{
				return false;
			}
		}else{
			return $portletObj;
		}
	}
}
?>